<?php
class scrollfollowWidget extends CWidget
{
	public $clientScript;
	
	public $baseUrl;
	public $Jscripts = array('jquery.scrollfollow.js');
	
	public $options;	//transition:"none", width:"75%", height:"75%"
	public $id = 'scroll';
   /**
    * Publishes the assets
    */
   public function publishAssets()
   {
      $dir = dirname(__FILE__).DIRECTORY_SEPARATOR.'assets';
 
      $this->baseUrl = Yii::app()->getAssetManager()->publish($dir);
   }
   
   /**
    * Registers the external javascript files
    */
   public function registerClientScripts()
   {
      if ($this->baseUrl === '')
         throw new CException('Can not find the base folder');

      $this->clientScript = Yii::app()->getClientScript();

      $this->clientScript->registerCoreScript('jquery');
      foreach ($this->Jscripts as $script)
      {
       $this->clientScript->registerScriptFile($this->baseUrl.'/'.$script,CClientScript::POS_END);     	
      }

   }
   
   public function renderScript()
   {
   		$script = "$('{$this->id}').css('position','relative').scrollFollow();";
   		Yii::app()->getClientScript()->registerScript(__CLASS__.'ready',$script,CClientScript::POS_READY);
   }
   
  
	public function run()
	{
		$this->publishAssets();
		$this->registerClientScripts();
		
		$this->renderScript();
	
//		$this->render($this->view);	
	}

}
?>